/*
 * The model files set the parameters for model
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sea.util;

import java.io.File;
import javax.swing.JTextArea;

/**
 *
 * The model files set the parameters for model
 * 
 * @author  Zhirun Ding
 * 
 * Created on 06/07/2012
 * 
 */

public class ModelFile {
    private String fullName = null;//primary key,auto generate
    private String path = "";//model file path
    private String fileName = null;
    private String modelType = null;//flat,hype,biopepa
    private String state = "";//opened,parsed
    private boolean isChanged = false;
    private String content;
    private JTextArea editTextArea;

    public ModelFile() {
    }
    
    public ModelFile(String path, String fileName, String state) {
        this.path = path;
        this.fileName = fileName;
        this.state = state;
        this.fullName = path + File.separator + fileName;
        this.identifyModelType();
    }
    
    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
        this.fullName = null;
    }

    public String getFullFilename() {
        if (this.fullName == null) {
            this.fullName = this.path + File.separator + this.fileName;
        }
        return fullName;
    }    

    public String getModelType() {
        if (modelType == null) {
            this.identifyModelType();
        }
//        if (fileName.endsWith(".hype")) {
//            modelType = "hype";
//        } else if (fileName.endsWith(".biopepa")) {
//            modelType = "biopepa";
//        } else {
//            modelType = "flat";
//        }
        return modelType;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
        this.fullName = null;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public boolean getIsChanged() {
        return isChanged;
    }

    public void setIsChanged(boolean isChanged) {
        this.isChanged = isChanged;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public JTextArea getEditTextArea() {
        return editTextArea;
    }

    public void setEditTextArea(JTextArea editTextArea) {
        this.editTextArea = editTextArea;
    }        
    
    
    private void identifyModelType() {
        sea.util.modeltype.ModelTypeParser parser = new sea.util.modeltype.ModelTypeParser();
        try {
            this.modelType = parser.parseFromFile(this.getFullFilename());
        } catch(Exception e) {
            System.err.println("Exception in identifying model type");
            this.modelType = "other";
        } catch (Error e) {
            System.err.println("Error in identifying model type");
            this.modelType = "other";
        }
    }
    
}
